package com.Servlet;

import com.dao.DaoFactory;
import com.entity.search;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

public class book_examine_dealServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setHeader("Cache-control", "no-cache");
        request.setCharacterEncoding("UTF-8");

        String state = request.getParameter("state");
        String bookname = request.getParameter("bookname");
        String author_name = request.getParameter("author_name");
        String types = request.getParameter("types");
        String brief_introduction = request.getParameter("brief_introduction");
        System.out.println("--------------审核书籍---------------");
        System.out.println("bookname:"+bookname);
        System.out.println("author_name:"+author_name);
        System.out.println("types:"+types);
        System.out.println("brief_introduction:"+brief_introduction);
        System.out.println("state:"+state);
        System.out.println("---------------------------------");

        if(state.equals("0")){
            System.out.println("未通过");
            try {
                DaoFactory.getInstance().getbook_examineDao().delBybookname(bookname);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        else {
            System.out.println("通过");
            search newbook = new search();
            newbook.setBrief_introduction(brief_introduction);
            newbook.setTypes(types);
            newbook.setAuthor_name(author_name);
            newbook.setBookname(bookname);

            try {
                DaoFactory.getInstance().getbook_examineDao().delBybookname(bookname);
            } catch (SQLException e) {
                e.printStackTrace();
            }

            try {
                DaoFactory.getInstance().getsearchDao().add(newbook);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        request.getRequestDispatcher("book_examine.jsp").forward(request,response);

    }
    }
